package org.hyson.gofun;
import android.graphics.Point;
import android.util.Log;
import java.io.Serializable;
public class Player implements Serializable{
	public enum human_action{
		WAIT,
		SET,
		KILL,
		SRC,
		DST,
		GO
	}

        protected  String name;
        protected  int free_pieces;

	protected  int kill_num;//记录当前有多少杀
	protected  Pieces kill_who;//记录杀敌人还是自杀

	protected  Point set_pos;
	protected  Point kill_pos;
	protected  Point src_pos;
        protected  Point dst_pos;
	protected  Board board;
	protected  Game game;

	protected human_action action;

        protected  boolean is_human;
        protected  Pieces who;
        public Player(Pieces who, int free_pieces, boolean is_human, Board board, Game game){
        		this.board = board;
        		this.game = game;
                this.who = who;
                this.free_pieces = free_pieces;
                this.is_human =  is_human;

                action = human_action.WAIT;

                kill_num = 0;
                kill_who = who;
                src_pos = new Point();
                src_pos.x = -1;
                src_pos.y = -1;
                dst_pos = new Point();

                dst_pos.x = -1;
                dst_pos.y = -1;
                set_pos = new Point();

                set_pos.x = -1;
                set_pos.y = -1;
                kill_pos = new Point();

                kill_pos.x = -1;
                kill_pos.y = -1;
        }
        public boolean isWait(){
        	return (action == human_action.WAIT);
        }
	public int getKillNum(){
		return kill_num;	
	}
	public void decKillNum(){
		kill_num--;	
		if(kill_num < 0){
			
		}
	}
	public void setKillNum(int kill_num){
		this.kill_num = kill_num;
	}
	public Pieces getKillWho(){
		return kill_who;
	}
	public void setKillWho(Pieces kill_who){
		this.kill_who = kill_who;
	}
        public boolean getIsHuman(){
                return is_human;
        }
        public Pieces getWho(){
                return who;
        }
        public boolean decFreePieces()
        {
                free_pieces--;
                if(free_pieces == 0)
                        return true;
                return false;
        }
        protected boolean getNextSet(Point set_pos){
        	set_pos.x = this.set_pos.x;
        	set_pos.y = this.set_pos.y;
        	return true;
        }
        protected boolean  getNextKill(Point kill_pos){
        	kill_pos.x = this.kill_pos.x;
        	kill_pos.y = this.kill_pos.y;
        	return true;
        }
        protected boolean getNextMove(Point src_pos, Point dst_pos){
			if(board.noMoves(who)){
				return false;
			}
        		src_pos.x = this.src_pos.x;
        		src_pos.y = this.src_pos.y;
        		dst_pos.x = this.dst_pos.x;
        		dst_pos.y = this.dst_pos.y;
			Log.d("Player", "this.src_pos = " + this.src_pos.x + " " + this.src_pos.y );
			Log.d("Player", "this.dst_pos = " + this.dst_pos.x + " " + this.dst_pos.y );

			Log.d("Player", "src_pos = " + src_pos.x + " " + src_pos.y );
			Log.d("Player", "dst_pos = " + dst_pos.x + " " + dst_pos.y );
	                return true;
        }
	public  void setNextSet(Point set_pos){
		this.set_pos.x = set_pos.x;
		this.set_pos.y = set_pos.y;
		action = human_action.SET;
	}
	public  void setNextKill(Point kill_pos){
		this.kill_pos.x = kill_pos.x;
		this.kill_pos.y = kill_pos.y;
		action = human_action.KILL;
	}
	public  void setNextSrc(Point src_pos){
		this.src_pos.x = src_pos.x;
		this.src_pos.y = src_pos.y;
		Log.d("Player", "Set src_pos = " + this.src_pos.x + " " + this.src_pos.y );
		action = human_action.SRC;
	}
	public  void setNextDst(Point dst_pos){
		this.dst_pos.x = dst_pos.x;
		this.dst_pos.y = dst_pos.y;
		Log.d("Player", "Set dst_pos = " + this.dst_pos.x + " " + this.dst_pos.y );
		action = human_action.DST;
	}
	public void setThink(){
		action = human_action.GO;
	}
	public  boolean thinkOver(){
		return false;
	}
        public String toString(){
                return name;
        }
}
